package hot_100;

public class 搜索旋转排序数组 {
    public static void main(String[] args) {

    }

    public int search(int[] nums, int target) {
        int n = nums.length;
        int l = 0, r = n - 1;
        while (r >= l) {
            int mid = (r + l) >> 1;
            if (nums[mid] == target)
                return mid;

            if (nums[mid] >= nums[l]) {
                if (target > nums[l] && target > nums[mid]) {
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            } else {
                if (target < nums[l] && nums[mid] < target) {
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }
        }
        return -1;
    }
}
